package domain.game;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import domain.worm.Worm;

public class Team {

	private List<Worm> worms;
	private List<Worm> deadWorms;
	private int currentWormId;
	private int teamId;
	private Color teamColor;;
	
	public Team(int i,Color c) {
		this.setWorms(new ArrayList<Worm>());
		this.deadWorms = new ArrayList<Worm>();
		this.setCurrentWormId(0);
		this.setTeamId(i);
		this.teamColor = c;
		this.notifyTeamId();
	}

	public void notifyTeamId() {
		for(Worm w:this.worms){
			w.setTeamId(this.teamId);
		}
	}

	public int getCurrentWormId() {
		return currentWormId;
	}

	public void setCurrentWormId(int currentWorm) {
		this.currentWormId = currentWorm;
	}

	public List<Worm> getWorms() {
		return worms;
	}

	public void setWorms(List<Worm> worms) {
		this.worms = worms;
	}
	
	public void addWorm(Worm worm){
		this.getWorms().add(worm);
	}
	public void nextWorm(){
		//CHEQUEAR QUE NO SE ROMPA
		if (this.getCurrentWormId() + 1 >= this.getWorms().size()){
			this.setCurrentWormId(0);
		}else{
			this.currentWormId++;
		}
		if (!this.getCurrentWorm().isAlive()){
			this.nextWorm();
		}
	}

	public int getTeamId() {
		return teamId;
	}

	public void setTeamId(int teamId) {
		this.teamId = teamId;
	}
	public Worm getCurrentWorm(){
		return this.getWorms().get(this.getCurrentWormId());
	}

	public boolean containsWorm(Worm worm) {
		return this.getWorms().contains(worm);
	}
	public void wormDied(Worm worm){
		//this.deadWorms.add(worm);

		this.worms.remove(worm);
	}
	public boolean defeated(){
		return this.worms.isEmpty();
	}

	public void setTeamColor(Color teamColor) {
		this.teamColor = teamColor;
	}

	public Color getTeamColor() {
		return teamColor;
	}
}
